
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2708
 * @Author : WangRuoyu 
 * @Date : 2023/6/1 9:08
 */

#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;

class Solution {
public:
    long long maxStrength(vector<int> &nums) {
        long long res = 1;
        sort(nums.begin(), nums.end());
        if (nums.size()==1){
            return nums[0];
        }
        if (nums[0] == 0 && nums[nums.size() - 1] == 0) {
            return 0;
        }
        if (nums[0] < 0 && nums[1] == 0 && nums[nums.size() - 1] == 0) {
            return 0;
        }
        for (int i = 0; i < nums.size(); ++i) {
            if (nums[i] < 0) {
                if (i + 1 < nums.size() && nums[i + 1] < 0) {
                    res *= ((long long) nums[i] * (long long) nums[i + 1]);
                    i++;
                }
            } else if (nums[i] > 0) {
                res *= (long long) nums[i];
            }
        }
        return res;
    }
};

int main() {

    return 0;
}